﻿using SDDLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace PSDServer
{
    public static class Settings
    {
        public static API API { get; private set; }
        public static string ApiServerAddress { get; private set; }
        public static int ListenPort { get; private set; }
        public static int SendPort { get; private set; }
        public static string LogPath { get; set; }
        static Settings()
        {
            API = new API();
        }

        public static bool Read()
        {
            try
            {
                ApiServerAddress = System.Configuration.ConfigurationManager.AppSettings["ApiServerAddress"];
                ListenPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ListenPort"]);
                SendPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SendPort"]);
                LogPath = System.Configuration.ConfigurationManager.AppSettings["LogPath"];

                foreach (var p in API.GetType().GetProperties())
                {
                    p.SetValue(API, ApiServerAddress + "api/VideoDownload/" + p.Name);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
